---------------------------------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  F:/Dropbox (UBC-Umich)/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data_historical/dataverse_files/code/logs/figure
> _A7_mnc_outward_manufserv.log
  log type:  text
 opened on:  28 Nov 2022, 07:02:17

. *-------------------------------------------------------------------------------
. 
. 
. 
. 
. *---------------------------------------------          
. *Output per worker 
. *---------------------------------------------
. use "${data}/aggregates_tfp_lp_klems_agg.dta", clear 

. keep year isocode ln_ctfp ln_gdp_pw_ppp 

. duplicates drop 

Duplicates in terms of all variables

(2,510 observations deleted)

. tempfile base0

. save `base0', replace 
(note: file C:\Users\VANESS~1\AppData\Local\Temp\ST_354_000026.tmp not found)
file C:\Users\VANESS~1\AppData\Local\Temp\ST_354_000026.tmp saved

. 
. use "${data}/aggregates_tfp_lp_klems_agg.dta", clear 

. keep year isocode type ln_LP_ppp_emp_pwt

. rename ln_LP_ppp_emp_pwt ln_lp_

. reshape wide ln_lp_ , i( year isocode ) j(type) string
(note: j = manuf market nonmarket others serv total)

Data                               long   ->   wide
-----------------------------------------------------------------------------
Number of obs.                     3012   ->     502
Number of variables                   4   ->       8
j variable (6 values)              type   ->   (dropped)
xij variables:
                                 ln_lp_   ->   ln_lp_manuf ln_lp_market ... ln_lp_total
-----------------------------------------------------------------------------

. duplicates drop 

Duplicates in terms of all variables

(0 observations are duplicates)

. tempfile base1

. save `base1', replace 
(note: file C:\Users\VANESS~1\AppData\Local\Temp\ST_354_000027.tmp not found)
file C:\Users\VANESS~1\AppData\Local\Temp\ST_354_000027.tmp saved

. 
. use `base0', clear

. merge 1:1 isocode year using `base1'

    Result                           # of obs.
    -----------------------------------------
    not matched                             0
    matched                               502  (_merge==3)
    -----------------------------------------

. drop _merge 

. keep if year==2016 
(463 observations deleted)

. tempfile productivity_agg

. save `productivity_agg', replace 
(note: file C:\Users\VANESS~1\AppData\Local\Temp\ST_354_000028.tmp not found)
file C:\Users\VANESS~1\AppData\Local\Temp\ST_354_000028.tmp saved

. 
. 
. use "${data}/aggregates_tfp_lp_klems.dta", clear 

. keep year isocode type sector1 sector ln_LP_ppp_emp_pwt

. rename ln_LP_ppp_emp_pwt ln_lp_sec

. duplicates drop 

Duplicates in terms of all variables

(0 observations are duplicates)

. merge m:1 isocode year using `productivity_agg'
(note: variable year was int, now double to accommodate using data's values)
(note: variable isocode was str2, now str32 to accommodate using data's values)

    Result                           # of obs.
    -----------------------------------------
    not matched                        11,540
        from master                    11,540  (_merge==1)
        from using                          0  (_merge==2)

    matched                               972  (_merge==3)
    -----------------------------------------

. keep if _merge==3
(11,540 observations deleted)

. drop _merge

. tempfile productivity

. save `productivity', replace 
(note: file C:\Users\VANESS~1\AppData\Local\Temp\ST_354_000029.tmp not found)
file C:\Users\VANESS~1\AppData\Local\Temp\ST_354_000029.tmp saved

. 
.         
.                 
. *---------------------------------------------
. *Outward Multinational*
. *---------------------------------------------
. use "${data}/klems_oecd_unido_orbis_sales_emp_exp.dta", clear

. keep year isocode  sector1 sector GO_usd_mnc_out

. keep if isocode=="DK" | isocode=="JP" | isocode=="IT" | isocode=="KR" | isocode=="DE" | isocode=="FR" | isocode=="ES" |  isocode=="MX" |  isocode
> =="GB" |  isocode=="PL" |  isocode=="GR" |  isocode=="NL" |  isocode=="RO" |  isocode=="BE" |  isocode=="AT" |  isocode=="PT" |  isocode=="FI" | 
>  isocode=="SE" |  isocode=="CZ" |  isocode=="SK" |  isocode=="BG" |  isocode=="HU" |  isocode=="HR" |  isocode=="LV" |  isocode=="SI" |  isocode=
> ="LT" |  isocode=="EE" 
(4,095 observations deleted)

. keep if year==2016
(8,100 observations deleted)

. drop if isocode=="KR" | isocode=="MX" 
(50 observations deleted)

. 
. gen GO_manuf= GO_usd_mnc_out if sector1=="Manufacturing (C)"
(482 missing values generated)

. gen GO_serv= GO_usd_mnc_out if sector1=="Market_Services (G-H-I-J-K-M-N-R-S-T)"
(471 missing values generated)

. gen GO_tot= GO_usd_mnc_out if sector1=="Total (TOT)"
(603 missing values generated)

. gen GO_market= GO_usd_mnc_out if sector1=="Market (MARKT)"
(603 missing values generated)

. drop if sector1=="Non-Market Economy"
(125 observations deleted)

. rename GO_usd_mnc_out GO_sec

. 
. gen GO_sec_fr=GO_sec if isocode=="FR"
(480 missing values generated)

. by year sector, sort: egen xx_max=max(GO_sec_fr)

. gen ln_ratio=ln(GO_sec/xx_max)
(75 missing values generated)

. drop GO_sec_fr GO_sec xx_max

. rename ln_ratio GO_sec

. 
. foreach ii in GO_manuf GO_serv GO_tot GO_market {
  2. display "`ii'"
  3. by year isocode, sort: egen xx=max(`ii')
  4. drop `ii'
  5. rename xx `ii'
  6. 
. gen `ii'_fr=`ii' if isocode=="FR"
  7. by year, sort: egen xx_max=max(`ii'_fr)
  8. gen ln_ratio=ln(`ii'/xx_max)
  9. drop `ii'_fr `ii' xx_max
 10. rename ln_ratio `ii'
 11. }
GO_manuf
(60 missing values generated)
(480 missing values generated)
(60 missing values generated)
GO_serv
(60 missing values generated)
(480 missing values generated)
(60 missing values generated)
GO_tot
(60 missing values generated)
(480 missing values generated)
(60 missing values generated)
GO_market
(60 missing values generated)
(480 missing values generated)
(60 missing values generated)

. *
. 
. drop if sector==sector1
(125 observations deleted)

. merge 1:1 isocode year sector using `productivity'
(note: variable year was int, now double to accommodate using data's values)
(note: variable isocode was str2, now str32 to accommodate using data's values)

    Result                           # of obs.
    -----------------------------------------
    not matched                           597
        from master                         0  (_merge==1)
        from using                        597  (_merge==2)

    matched                               375  (_merge==3)
    -----------------------------------------

. drop if _merge==2
(597 observations deleted)

. drop _merge

. tempfile out_mnc

. save `out_mnc', replace 
(note: file C:\Users\VANESS~1\AppData\Local\Temp\ST_354_00002a.tmp not found)
file C:\Users\VANESS~1\AppData\Local\Temp\ST_354_00002a.tmp saved

. 
. 
. *Only aggregates* 
. *------------------------------------------
. use `out_mnc', clear

. keep year isocode  GO_manuf GO_serv GO_tot GO_market

. duplicates drop

Duplicates in terms of all variables

(350 observations deleted)

. merge 1:1 isocode year using `productivity_agg'

    Result                           # of obs.
    -----------------------------------------
    not matched                            14
        from master                         0  (_merge==1)
        from using                         14  (_merge==2)

    matched                                25  (_merge==3)
    -----------------------------------------

. drop if _merge==2
(14 observations deleted)

. drop _merge

. tempfile out_mnc_sec

. save `out_mnc_sec', replace
(note: file C:\Users\VANESS~1\AppData\Local\Temp\ST_354_00002b.tmp not found)
file C:\Users\VANESS~1\AppData\Local\Temp\ST_354_00002b.tmp saved

. 
. 
. 
. *---------------------------------------------
. *PHI*
. *---------------------------------------------
. local nn=10 

. local yy=2016

. *minimum number of sectors allowed per year-isocode*/
. clear all

. use "${data}/estimates_sec_naics_sales_s1_base_woparent.dta", clear

. keep if year==`yy'
(4,828 observations deleted)

. rename DA D_A

. drop if D_A==. | (D_A==0 & isocode!="FR")
(1 observation deleted)

. tab type

       type |      Freq.     Percent        Cum.
------------+-----------------------------------
      manuf |        162       34.03       34.03
  nonmarket |         74       15.55       49.58
     others |         78       16.39       65.97
       serv |        162       34.03      100.00
------------+-----------------------------------
      Total |        476      100.00

. 
. keep isocode year type sector1 sector D_A

. rename D_A D_A_sec

. merge m:1 year isocode using "${data}/estimates_agg_naics_sales_s1_base_woparent.dta", keepusing(D_A)
(note: variable year was int, now float to accommodate using data's values)

    Result                           # of obs.
    -----------------------------------------
    not matched                           296
        from master                         0  (_merge==1)
        from using                        296  (_merge==2)

    matched                               476  (_merge==3)
    -----------------------------------------

. rename D_A D_A_agg

. drop if _merge==2
(296 observations deleted)

. drop _merge

. merge m:1 year isocode type using "${data}/estimates_aggtype_naics_sales_s1_base_woparent.dta", keepusing(D_A)

    Result                           # of obs.
    -----------------------------------------
    not matched                            74
        from master                        74  (_merge==1)
        from using                          0  (_merge==2)

    matched                               402  (_merge==3)
    -----------------------------------------

. rename D_A D_A_type

. drop if _merge==2
(0 observations deleted)

. drop _merge

. 
. gen D_A_manuf=D_A_type if sector1=="Manufacturing (C)"
(314 missing values generated)

. gen D_A_serv=D_A_type if sector1=="Market_Services (G-H-I-J-K-M-N-R-S-T)"
(314 missing values generated)

. gen D_A_others=D_A_type if sector1=="Other_Goods (A-B-D-E-F)"
(399 missing values generated)

. rename D_A_agg D_A_tot

. drop D_A_type

. 
. foreach ii in D_A_manuf D_A_serv D_A_others  {
  2. display "`ii'"
  3. by year isocode, sort: egen xx=max(`ii')
  4. drop `ii'
  5. rename xx `ii'
  6. }
D_A_manuf
D_A_serv
D_A_others
(15 missing values generated)

. *
. 
. *Bring MNC information
. *-------------------------------- 
. merge 1:1 year isocode sector using `out_mnc'
(note: variable year was float, now double to accommodate using data's values)
(note: variable isocode was str2, now str32 to accommodate using data's values)
(note: variable sector was str26, now str37 to accommodate using data's values)

    Result                           # of obs.
    -----------------------------------------
    not matched                           107
        from master                       104  (_merge==1)
        from using                          3  (_merge==2)

    matched                               372  (_merge==3)
    -----------------------------------------

. keep if _merge==3
(107 observations deleted)

. drop _merge

. 
. gen D_A_tot_phi=(-1)*D_A_tot*(0.2)

. gen b_D_A_tot_phi_`grvar0'=ln_gdp_pw_ppp - D_A_tot_phi 

. 
. gen D_A_manuf_phi=(-1)*D_A_manuf*(0.2)

. gen b_D_A_manuf_phi_`grvar0'=ln_lp_manuf - D_A_manuf_phi

. 
. gen D_A_serv_phi=(-1)*D_A_serv*(0.2)

. gen b_D_A_serv_phi_`grvar0'=ln_lp_serv - D_A_serv_phi

. 
. gen D_A_sec_phi=(-1)*D_A_sec*(0.2)

. gen b_D_A_sec_phi_`grvar0'=ln_lp_sec - D_A_sec_phi

. 
. drop D_A_sec D_A_tot D_A_manuf D_A_serv D_A_others 

. tempfile fig5

. save `fig5', replace
(note: file C:\Users\VANESS~1\AppData\Local\Temp\ST_354_00002c.tmp not found)
file C:\Users\VANESS~1\AppData\Local\Temp\ST_354_00002c.tmp saved

. 
. 
. *---------------------------------------------
. *Sector graph: 
. *---------------------------------------------
. use `fig5', clear

. gen rhs1=D_A_manuf_phi-D_A_serv_phi

. gen rhs2=b_D_A_manuf_phi-b_D_A_serv_phi

. gen lhs=GO_manuf-GO_serv
(45 missing values generated)

. by isocode year, sort: gen a=_n==1

. keep if a==1
(347 observations deleted)

. drop a

. 
. local LHS lhs 

. local RHS1 rhs1

. local RHS2 rhs2

. drop if `LHS'==.
(3 observations deleted)

. 
. sum `LHS' `RHS1' `RHS2'

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
         lhs |         22   -.4877717    .9448969  -2.387148    .927053
        rhs1 |         22    .0095053    .1126127  -.1868064   .3672589
        rhs2 |         22   -.1472889    .2086052  -.6140867   .3207409

. local xtitle "{&Delta}`=ustrunescape("\u03D5\u0303")'{sub:manuf,n}-{&Delta}`=ustrunescape("\u03D5\u0303")'{sub:serv,n}"

. local ytitle "{&Delta}rca{sub:manuf,n}-{&Delta}rca{sub:serv,n}"

. 
. *------------------------------------
. local clusterlist "robust"

. gen ss=1

. local abslist "ss"

. 
. reghdfe `LHS' `RHS1', abs(`abslist') 
(MWFE estimator converged in 1 iterations)

HDFE Linear regression                            Number of obs   =         22
Absorbing 1 HDFE group                            F(   1,     20) =       8.24
                                                  Prob > F        =     0.0095
                                                  R-squared       =     0.2917
                                                  Adj R-squared   =     0.2563
                                                  Within R-sq.    =     0.2917
                                                  Root MSE        =     0.8149

------------------------------------------------------------------------------
         lhs |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        rhs1 |   4.531807   1.579023     2.87   0.009     1.238023     7.82559
       _cons |  -.5308479   .1743768    -3.04   0.006    -.8945915   -.1671044
------------------------------------------------------------------------------

Absorbed degrees of freedom:
-----------------------------------------------------+
 Absorbed FE | Categories  - Redundant  = Num. Coefs |
-------------+---------------------------------------|
          ss |         1           0           1     |
-----------------------------------------------------+

. mat b = e(b)

. mat V = e(V)

. global c1: display %-03.2fc round(b[1,1],0.001)

. global se1: display %-03.2fc round(sqrt(V[1,1]),0.001)

. global rsq1: display %-03.2fc round(`e(r2)',0.001)

. 
. display $c1
4.53

. display $se1
1.58

. display $rsq1
.29

. 
. 
. global opt1 msymbol(circle_hollow) mlabel(isocode) mlabcolor(red)  msize(smaller) mlabsize(small)

. global opt2 msymbol(square_hollow) mlabel(isocode) mlabcolor(blue) msize(smaller) mlabsize(small)

. two (scatter `LHS' `RHS1', sort $opt1  mcolor(red)) (lfit `LHS' `RHS1', lcolor(red)) (line `RHS1' `RHS1', lcolor(none)) , ylabel(-3(1)1, format(%
> 5.1f) labsize(medlarge)) xlabel(-0.2(0.2)0.4, format(%5.1f) labsize(medlarge)) ///
>         title("", size(small)) ytitle("`ytitle'", size(medlarge)) xtitle("`xtitle'", size(medlarge)) graphregion(fcolor(white) lcolor(white)) ///
>         legend(order(2 "$c1 ($se1), R2: $rsq1" ) rows(2) size(medlarge) bplace(se) ring(0) region(lwidth(none))) 
(note:  named style smaller not found in class symbolsize, default attributes used)

. 
. graph export "${rappendix}/fig_A7_mnc_outward_manufserv.pdf", replace
(file F:/Dropbox (UBC-Umich)/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data_historical/dataverse_files/results/appendix/fig_A7
> _mnc_outward_manufserv.pdf written in PDF format)

. 
. 
. log close 
      name:  <unnamed>
       log:  F:/Dropbox (UBC-Umich)/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data_historical/dataverse_files/code/logs/figure
> _A7_mnc_outward_manufserv.log
  log type:  text
 closed on:  28 Nov 2022, 07:02:22
---------------------------------------------------------------------------------------------------------------------------------------------------
